package com.java.simple.study.juc.p3;

import com.java.simple.study.tool.Sleeper;
import lombok.extern.slf4j.Slf4j;

/**
 * @author zhoujl
 * @date 2022/5/10 21:18
 * @desc
 */
@Slf4j(topic = "c.TestLiveLock")
public class TestLiveLock {

    static volatile int count = 13;

    public static void main(String[] args) {
        new Thread(() -> {
            // 期望减到0 退出循环
            while (count > 0) {
                Sleeper.sleep(0.5);
                count--;
                log.debug("count:{}", count);
            }
        }, "t1").start();

        new Thread(() -> {
            // 期望达到20 退出循环
            while (count < 20) {
                Sleeper.sleep(0.5);
                count++;
                log.debug("count:{}", count);
            }
        }, "t2").start();
    }

}
